package com.look.uiliberary;


import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import java.util.LinkedList;
import java.util.List;

import cn.pedant.SweetAlert.SampleActivity;


public class MainActivity extends Activity {



	private ListView listView;
	// i am comming now
	//good
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_debug);
        listView = (ListView)findViewById(R.id.debug_listview);
        listView.setAdapter(new DebugListViewAdapter(getItems()));
        listView.setOnItemClickListener(new OnItemClickListener()
        {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				
				DebugItem item = (DebugItem)arg1.getTag();
				if(null != item)
				{
					item.getListener().onClick(null);
				}
				
			}
        	
        });
    }


    
    private List<DebugItem> getItems()
    {
    	List<DebugItem> items = new LinkedList<DebugItem>();
    	
    	 
    	items.add(new DebugItem("�鿴���ֶԻ���",new OnClickListener()
     	{

 			@Override
 			public void onClick(View arg0) {
 				Intent intent = new Intent(getApplicationContext(),SampleActivity.class);
 				startActivity(intent);
 			}
     		
     	}));
    	
    	
    	

    	return items;
    }
    
    class  DebugListViewAdapter extends BaseAdapter
    {

    	private List<DebugItem> items;
    	
    	public DebugListViewAdapter(List<DebugItem> items)
    	{
    		this.items = items;
    	}
    	
		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return items.size();
		}

		@Override
		public Object getItem(int arg0) {
			// TODO Auto-generated method stub
			return items.get(arg0);
		}

		@Override
		public long getItemId(int arg0) {
			// TODO Auto-generated method stub
			return arg0;
		}

		@Override
		public View getView(int arg0, View arg1, ViewGroup arg2) {
			
			TextView tmView = null;
			if(arg1 == null){
				TextView tm = new TextView(getApplicationContext());
				tm.setBackgroundColor(Color.BLACK);
				tm.setTextSize(28);
				tmView = tm;
				tmView.setTag(getItem(arg0));
				tmView.setText(items.get(arg0).getTitle());
				}else {
				tmView = (TextView)arg1;
				tmView.setText(items.get(arg0).getTitle());
			}

			return tmView;
		}
    	
    }
    
    public static class DebugItem
    {
    	private String title;
    	private OnClickListener listener;
		public String getTitle() {
			return title;
		}
		public void setTitle(String title) {
			this.title = title;
		}
		public OnClickListener getListener() {
			return listener;
		}
		public void setListener(OnClickListener listener) {
			this.listener = listener;
		}
		public DebugItem(String title, OnClickListener listener) {
			super();
			this.title = title;
			this.listener = listener;
		}
		public DebugItem() {
			super();
		}
		
    	
    }

}
